package com.hu.ta.assignment5.beans;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class NGrams extends java.util.HashMap<NGram, PosProbabilities> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2186456145722294208L;

	public PosProbabilities getFirstEntry() {
		//if (size()>0) 
		{
			return entrySet().iterator().next().getValue();
		}
	}
	
	public String[] getAllTags() {
		Set<String> set = new HashSet<String>();
		for (NGram ngram : keySet()) {
			set.add(ngram.poses[NGram.NGRAM_SIZE-1]);
		}
		
		String strs[] = new String[set.size()];
		return set.toArray(strs);
	}
	
	public NGram[] getAllNGrams() {
		NGram ngrams[] = new NGram[size()];
		return keySet().toArray(ngrams);
	}
	
	@Override
	public String toString() {
		String ret = "";		
		for (Map.Entry<NGram, PosProbabilities> g : entrySet()) {
			String key = g.getKey().toString();
			for (String str : g.getValue().toStrings() ) {
				ret += key + "\t" + str;
			}
		}
		ret += "\n";
		return ret;
	}
}
